package yf.asserts;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.etsi.uri.x01903.v13.impl.ResponderIDTypeImpl;
import org.testng.Assert;
import yf.utils.GetFileMess;

import static yf.asserts.ResponseAssert.verfiyResult;
import static yf.report.TestStep.assertRespond;
import static yf.report.TestStep.requestAndRespondBody;

public class Asserts {
public static void asserts(String caseMessMap, String bodyString, Response response){
    String caseNo=new GetFileMess().getCaseMessKeyValue(caseMessMap, "caseNo");
    String testPoint=new GetFileMess().getCaseMessKeyValue(caseMessMap, "testPoint");
    String path=new GetFileMess().getCaseMessKeyValue(caseMessMap,"path");
    String url = RestAssured.baseURI + ":" + RestAssured.port + "/"+path ;
    requestAndRespondBody(caseNo,testPoint,url,bodyString,response.asString());
    boolean assertFlag = true;
    StringBuffer stringBufferResult = new StringBuffer();
    String expResult=new GetFileMess().getCaseMessKeyValue(caseMessMap, "result");
    //响应报文断言
    stringBufferResult = verfiyResult(expResult, response.asString());
    assertRespond(stringBufferResult);
    if (stringBufferResult.indexOf("断言false") != -1) {
        assertFlag = false;
    }
    //断言
    Assert.assertTrue(assertFlag, "响应报文断言或数据库断言失败，请查看断言结果！");


}
}
